

//
//  CSPaymentWayCell.m
//  SHCloudStore
//
//  Created by SH_iOS on 2017/4/12.
//  Copyright © 2017年 SH. All rights reserved.
//
#import "UIButton+EnlargeTouchArea.h"
#import "CSCustomPayWaysModel.h"
#import "CSPaymentWayCell.h"

@implementation CSPaymentWayCell{
    
    SHButton *_leftActionBtn;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self configUI];
        
    }
    return self;
}

-(void)configUI{
    
    self.icon = [[UIImageView alloc]init];
    self.icon.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.icon];
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = KSystemFont(__I6Width(11));
    self.nameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    [self.contentView addSubview:self.nameLabel];
    
    self.contentLabel = [[UILabel alloc]init];
    self.contentLabel.font = KSystemFont(__I6Width(10));
    self.contentLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    [self.contentView addSubview:self.contentLabel];
    
//    self.selectedImage = [[UIImageView alloc]init];
//    self.selectedImage.layer.borderColor = [UIColor colorWithHexString:@"#999999"].CGColor;
//    self.selectedImage.layer.borderWidth = 0.5;
//    self.selectedImage.layer.cornerRadius = __I6Width(12);
//    self.selectedImage.layer.masksToBounds = YES;
//    
//    [self.contentView addSubview:self.selectedImage];
//    self.newicon = [[UIImageView alloc]init];
//    [self.contentView addSubview:self.newicon];
    
    _redRateBtn  = [SHButton buttonWithType:UIButtonTypeCustom] ;
    
    _redRateBtn.backgroundColor = KREDCOLOR;
   
    [_redRateBtn setTitle:@"1" font:9 titleColor:[UIColor whiteColor] textAlignment:(UIControlContentHorizontalAlignmentCenter) forState:UIControlStateNormal] ;
   
    [self.contentView addSubview:_redRateBtn];
    
    _arrowImgView = [[UIImageView alloc]init];
    _arrowImgView.image = [UIImage imageNamed:@"jmarrow"];
    [self.contentView addSubview:_arrowImgView];
    
    _statuBtn = [SHButton buttonWithType:UIButtonTypeCustom title:@"确认支付" font:14 titleColor:KREDCOLOR textAlignment:UIControlContentHorizontalAlignmentCenter forState:UIControlStateNormal];
    _statuBtn.userInteractionEnabled = NO;
    [self.contentView addSubview:_statuBtn];
   
    _leftActionBtn = [SHButton buttonWithType:UIButtonTypeCustom];
//    [leftActionBtn  setEnlargeEdgeWithTop:15 right:100 bottom:30 left:50];
//    _leftActionBtn.backgroundColor = [UIColor orangeColor];
    [_leftActionBtn addTarget:self action:@selector(redRateBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:_leftActionBtn];
    
}
- (void)layoutSubviews{
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(__I6Width(25));
        make.height.mas_equalTo(__I6Height(25));
        make.left.mas_equalTo(self.mas_left).with.offset(__I6Width(15));
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(__I6Height(10));
        make.left.mas_equalTo(self.icon.mas_right).with.offset(__I6Width(15));
        make.top.mas_equalTo(self.mas_top).with.offset(__I6Height(15));
    }];
    
    [self.newicon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(__I6Width(27));
        make.height.mas_equalTo(__I6Height(11));
        make.left.mas_equalTo(self.nameLabel.mas_right).with.offset(__I6Width(- 10));
        make.top.mas_equalTo(self.mas_top).with.offset(__I6Height(8));
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(__I6Width(200));
        make.height.mas_equalTo(__I6Height(10));
        make.left.mas_equalTo(self.icon.mas_right).with.offset(__I6Width(15));
        make.top.mas_equalTo(self.nameLabel.mas_bottom).with.offset(__I6Height(5));
    }];
    
   
    
    
//    [self.selectedImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(__I6Width(24));
//        make.height.mas_equalTo(__I6Width(24));
//        make.right.mas_equalTo(self.contentView.mas_right).with.offset(__I6Width(-15));
//        make.centerY.mas_equalTo(self.contentView.mas_centerY);
//    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = KLINECOLOR;
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(__I6Width(0));
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(__I6Width(0));
            make.height.mas_equalTo(__I6Height(0.5));
        make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(__I6Height(0));
    }];
    
    [_arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
       make.centerY.mas_equalTo(self.contentView.mas_centerY);
    make.right.mas_equalTo(self.contentView.mas_right).mas_offset(__I6Width(-15));
        make.width.mas_equalTo(__I6Height(8));
        make.height.mas_equalTo(__I6Height(14));
    }];
    
    [_statuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(__I6Width(-38));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        
    }];
    
    [_leftActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(0);
        make.top.mas_equalTo(self.contentView.mas_top).with.offset(0);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(0);

            make.width.mas_equalTo(120);
        
    }];
    
    
    
}
- (void)setCustomPayWaysModel:(CSCustomPayWaysModel *)customPayWaysModel{

    _customPayWaysModel = customPayWaysModel;
    
    if (customPayWaysModel.deposit_logo == nil) {
        
        self.icon.image  = [UIImage imageNamed:customPayWaysModel.image];
    }else{
        
        [self.icon sd_setImageWithURL:[NSURL URLWithString:customPayWaysModel.deposit_logo]];
    }
  
    self.nameLabel.text = customPayWaysModel.title;
    self.contentLabel.text = customPayWaysModel.sub_title;
    
    [self.statuBtn setTitle:_customPayWaysModel.use_title forState:UIControlStateNormal];
    [self.statuBtn setTitleColor:[UIColor colorWithHexString:_customPayWaysModel.use_color] forState:UIControlStateNormal];
    if (_customPayWaysModel.red_point ) {
        
        [_redRateBtn setTitle:customPayWaysModel.red_content forState:UIControlStateNormal];
        _redRateBtn.hidden = NO;
        
    }else{
        
        _redRateBtn.hidden = YES;

    }
    
//    if ([model.selected isEqualToNumber:@(1)]) {
//        [self.selectedImage setImage:[UIImage imageNamed:@"cs_check"]];
//        self.selectedImage.layer.borderWidth = 0;
//    }else{
//        [self.selectedImage setImage:[UIImage imageNamed:@""]];
//        self.selectedImage.layer.borderWidth = 0.5;
//    }
    CGFloat rateMsgW = [SHHelper widthOfString:customPayWaysModel.red_content font:KSHSystemFont(13) height:__I6Width(13)];
    [_redRateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.nameLabel.mas_right).with.offset(-2);
    make.bottom.mas_equalTo(self.nameLabel.mas_top).with.offset(__I6Width(5));
        make.width.mas_equalTo(rateMsgW);
        make.height.mas_equalTo(__I6Height(13));
        
    }];
    _redRateBtn.layer.cornerRadius = __I6Height(13)/2;
    _redRateBtn.layer.masksToBounds = YES;
}


- (void)redRateBtnAction:(UIButton *)sender{
    
   
    if (_delegate && [_delegate respondsToSelector:@selector(paymentWayCell:showRateMsg:)]) {
        
        [_delegate paymentWayCell:self showRateMsg:_customPayWaysModel.instructions];
    }
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    
    [super setSelected:selected animated:animated];
    if (selected) {
        
        self.layer.backgroundColor = [UIColor colorWithWhite:242/255.0 alpha:1].CGColor;
        
    }else{
        
        self.layer.backgroundColor = [UIColor whiteColor].CGColor;
        
    }
}

@end
